import { EmptyUserInfo, UserInfo } from "./../entity/interface/userInfo";
import { Local } from "@/entity/helper/storage.helper";
import { defineStore } from "pinia";
import { reactive, ref } from "vue";

export const useUserStore = defineStore("User", () => {
  const isLogin = ref((Local.get("isLogin") as boolean) || false);
  const setIsLogin = (value: boolean) => {
    isLogin.value = value;
    Local.set("isLogin", isLogin);
  };
  const userInfo = ref<UserInfo>(Local.get("userInfo") || EmptyUserInfo());
  const getUserInfo = () => userInfo.value;
  const setUserInfo = (params: UserInfo) => {
    userInfo.value = params;
    Local.set("userInfo", userInfo.value);
  };
  return {
    isLogin,
    setIsLogin,
    getUserInfo,
    setUserInfo,
  };
});
